Function Reference

_AD_GetLastLoginDate

Returns the lastlogin information for user and computer accounts from all DCs using the SamAccountName.

#Include <AD.au3>
_AD_GetLastLoginDate([$sObject = @Username[, $sSite = ""[, $aDCList = ""]]])

 

Parameters

$sObject Optional: SamAccountName of a user or computer account to get the last login date (default = @Username).
$sSite Optional: Only query DCs that belong to this site(s) (default = all sites).
This can be a single site or a list of sites separated by commas
$aDCList Optional: one-based two dimensional array of Domain Controllers as returned by function _AD_ListDomainControllers (default = "")

 

Return Value

Success: Last login date returned as YYYYMMDDHHMMSS. @extended is set to the total number of Domain Controllers.
    @error could be > 0 and contains the number of DCs that could not be reached or returns no data
Failure: 0, sets @error to:
    1 - $sObject could not be found. @extended = 0
    2 - $sObject has never logged in to the domain. @extended = 0
    3 - $aDCList has to be an array or blank
    4 - $aDCList has to be a 2-dimensional array
Warning: Last login date returned as YYYYMMDDHHMMSS (see Success), sets @error and @extended to:
    x - Number of DCs which could not be reached. Result is returned from all available DCs. @extended is set to the total number of Domain Controllers

 

Remarks

If it takes (too) long to get a result either some DCs are down or you have too many DCs in your AD.
+Case one: Please check @error and @extended as described above
+Case two: Specify parameter $sSite to reduce the number of DCs to query and/or retrieve the list of DCs yourself and pass the array as parameter 3

 

Related

 

See Also

http://blogs.technet.com/b/askds/archive/2009/04/15/the-lastlogontimestamp-attribute-what-it-was-designed-for-and-how-it-works.aspx

 

Example


#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#include <AD.au3>

; Open Connection to the Active Directory
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

; *****************************************************************************
; Example 1
; Get last login date for current user. Returned as YYYYMMDDHHMMSS
; *****************************************************************************
Global $iLLDate = _AD_GetLastLoginDate()
MsgBox(64, "Active Directory Functions - Example 1", "Last Login Date for User '" & @UserName & "'" & @CRLF & $iLLDate)

; *****************************************************************************
; Example 2
; Get last login date for current computer. Returned as YYYYMMDDHHMMSS
; *****************************************************************************
$iLLDate = _AD_GetLastLoginDate(@ComputerName & "$")
MsgBox(64, "Active Directory Functions - Example 2", "Last Login Date for Computer '" & @ComputerName & "$'" & @CRLF & $iLLDate)

; Close Connection to the Active Directory
_AD_Close()